const redis = require("redis");
const options = {
  host: "192.168.4.75",
  port: 15001,
  password: "123456",
  detect_buffers: true,  // 建议把这个选项设置成true
  retry_strategy: function(options) {
    if (options.error && options.error.code === "ECONNREFUSED") {
      // End reconnecting on a specific error and flush all commands with
      // a individual error
      return new Error("The server refused the connection");
    }
    if (options.total_retry_time > 1000 * 60 * 60) {
      // End reconnecting after a specific timeout and flush all commands
      // with a individual error
      return new Error("Retry time exhausted");
    }
    if (options.attempt > 10) {
      // End reconnecting with built in error
      return undefined;
    }
    // reconnect after
    return Math.min(options.attempt * 100, 3000);
  },
}

const client = redis.createClient(options);
client.on("error", function(error) {
  console.error(error);
});
 
client.set("key", "valueaaaa", redis.print);
const res = client.get("key", redis.print);

client.get("key", function(err, reply) {
  console.log('aaaa', reply.toString()); // Will print `OK`
});
